﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;

using System.ServiceModel;
using Teenusekiht;

public partial class SiteMaster : System.Web.UI.MasterPage
{
    bool loggedOut = false;

    protected void Page_Load(object sender, EventArgs e)
    {
        //LISATUD: Ajutine ja ebaeffektiivne kohvikute loetelu lisamine menüüsse

        //IService1 sc = new ChannelFactory<IService1>("Serv").CreateChannel();
        //KohvikType [] kohvikud = sc.Kohvikud(Rakendus.RAKENDUSE_KOOD).ToArray();

        //MenuItem mi ;
        //MenuItem main = new MenuItem ( "Kõik kohvikud" ) ;
        //NavigationMenu . Items . Add ( main ) ;

        //foreach ( KohvikType kohvik in kohvikud ) {
        //    mi = new MenuItem ( kohvik . KohvikuNimi ) ;
        //    mi . NavigateUrl = "~/Kohvik/Menu.aspx?kohvik=" + kohvik . Kohviku_ID ;
        //    main . ChildItems . Add ( mi ) ; }


        lblYear.Text = "" + DateTime.Now.Year;

        // Debug.Print(Page.User.Identity.Name);
        //if (Session["sess"] == null) Session["sess"] = SessionStatic.CreateSession();
        //SessionData sesDat = SessionStatic.GetData((int)Session["sess"]);
        //NavigationMenu.Items[1].Enabled = (sesDat.UserId != null) ;
    }   


    protected void LoggedOut(object sender, EventArgs e)
    {
        loggedOut = true;
        //Response.Redirect("~/Kohvik/LogOut.aspx");
    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (loggedOut)
        {
            if (Session["sess"] != null) SessionStatic.DestroySession((int)Session["sess"]) ;
            Session.Clear();
            Response.Redirect("~/Kohvik/LogOut.aspx");
        }
    }

    protected void HeadLoginName_Load(object sender, EventArgs e)
    {
        Debug.Print("LoginName.Controls.Count: " + (sender as LoginName).Controls.Count);
    }

}
